package taskshare.service;

import java.util.HashSet;
import java.util.Set;

import org.slim3.datastore.Datastore;

import taskshare.model.Comment;
import taskshare.model.Task;

import com.google.appengine.api.datastore.Key;

public class TaskService {

    CommentService commentService = new CommentService();

    public Task get(Key key) {
        Task task = Datastore.get(Task.class, key);
        task.setCommentList(commentService.getList(task.getCommentKeyList()));

        return task;
    }

    public void put(Task task) {
        Set<Key> commentKeyList = new HashSet<Key>();

        for (Comment comment : task.getCommentList()) {
            Datastore.put(comment);

            commentKeyList.add(comment.getKey());
        }

        task.setCommentKeyList(commentKeyList);
        Datastore.put(task);
    }

}
